package org.sn.jdish.spring.springboot.client;

import java.util.Collection;
import java.util.concurrent.TimeUnit;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

@Component
public class RedisClient<T> {

	@Autowired
	private RedisTemplate<String, T> redisTemplate;

	public Boolean hasKey(String key) {
		return redisTemplate.hasKey(key);
	}

	public void set(String key, T value) {
		redisTemplate.opsForValue().set(key, value);
	}

	public void set(String key, T value, int timelength, TimeUnit timeUnit) {
		redisTemplate.opsForValue().set(key, value, 10, timeUnit);
	}

	public T get(String key) {
		return redisTemplate.opsForValue().get(key);
	}

	public void delete(String key) {
		redisTemplate.delete(key);
	}

	public void delete(Collection<String> keys) {
		redisTemplate.delete(keys);
	}

	public Long getExpire(String key) {
		return redisTemplate.getExpire(key);
	}

	public Long getExpire(String key, TimeUnit timeUnit) {
		return redisTemplate.getExpire(key, timeUnit);
	}
}
